﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using ProgrammersCalculator.Common;
namespace ProgrammersCalculator.Convertor
{
    public class StringToBinary : IMultiValueConverter
    {
      
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((values[0] == null) || (values[1] == null))
            {
                return false;
            }
            string result = string.Empty;
            string data = values[0].ToString();
            if (data == "")
                return null;
            if (values[1].ToString() != "H")
                result = Encoding.UTF8.GetBytes(data).ByteToHexString();
            else
                result = data.StringToBinary();
            return result;

        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
